﻿#include "stdafx.h"
#include "UserInfoDlg.h"
#include "ui_UserInfoDlg.h"

#include "FrameHelper.h"

UserInfoDlg::UserInfoDlg(QWidget *parent)
	: QDialog(parent)
{
	ui = new Ui::UserInfoDlg();
	ui->setupUi(this);

	pFrameHelper = new FrameHelper(this);
	pFrameHelper->addDragWidget(this);
}

UserInfoDlg::~UserInfoDlg()
{
	delete ui;
}

void UserInfoDlg::expandTree(int depth)
{
	if (depth == -1)
		ui->treeUser->expandAll();
	else
		ui->treeUser->expandToDepth(depth);
}

void UserInfoDlg::setRecordModel(QAbstractItemModel * model)
{
	ui->treeUser->setModel(model);
}

UserInfo UserInfoDlg::getCurrentUserInfo()
{
	return userInfo;
}

void UserInfoDlg::on_btnOK_clicked()
{
    const QModelIndex & index = ui->treeUser->currentIndex();
	userInfo.strUserID   = index.data(TREE_ROLE_ID).toString();
	userInfo.strUserCode = index.data(TREE_ROLE_USERCODE).toString();
	userInfo.strUserName = index.data(TREE_ROLE_USERNAME).toString();
	userInfo.strDeptName = index.data(TREE_ROLE_DEPTNAME).toString();
	userInfo.strDeptID = index.data(TREE_ROLE_PID).toString();
	userInfo.strUserPasswd = index.data(TREE_ROLE_PASSWD).toString();
	accept();
}

void UserInfoDlg::on_btnCancel_clicked()
{
	this->close();
}
